#!/bin/bash

set -x

sudo adb kill-server
adb wait-for-device
sudo adb start-server
adb wait-for-device

adb root
adb wait-for-device
adb remount
adb wait-for-device

set -

adb devices | grep -q 'no permissions'
if [ 0 -eq $? ] ; then
    echo "no permissions, try again"
    exit 111
else
    adb devices
fi

exit 0
